/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Items.java
 *
 * Created on Sep 9, 2010, 2:10:32 AM
 */

package GUI;

import BusinessLogic.SalesMenFunction_BL;
import javax.swing.table.TableModel;

/**
 *
 * @author MrToan
 */
public class Items extends javax.swing.JFrame {

    /** Creates new form Items */
    public Items() {
        initComponents();
        GetItemTableValues();
    }
    SalesMenFunction_BL function_BL=new SalesMenFunction_BL();
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbItem = new javax.swing.JTable();
        bntSelect = new javax.swing.JButton();

        tbItem.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbItemMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbItem);

        bntSelect.setText("Select");
        bntSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntSelectActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(252, 252, 252)
                .addComponent(bntSelect)
                .addContainerGap(270, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bntSelect)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tbItemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbItemMouseClicked
        // TODO add your handling code here:
        Count=tbItem.getSelectedRow();
    }//GEN-LAST:event_tbItemMouseClicked

    private void bntSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntSelectActionPerformed
        // TODO add your handling code here:
        SalesMen.txtItem.setText((String)tbItem.getValueAt(Count, 0));
        String price=(String)tbItem.getValueAt(Count, 5);
        SalesMen.txtBPrice.setText(price);

        if(!SalesMen.txtBQuantity.getText().equals(""))
        {
            float total=Float.parseFloat(price);
            int quantity=Integer.parseInt(SalesMen.txtBQuantity.getText());

            float TotalPrice=total*quantity;
            String TP=String.valueOf(TotalPrice);
            SalesMen.txtTotalPrice.setText(TP);
        }
        
        this.dispose();
    }//GEN-LAST:event_bntSelectActionPerformed


    public void GetItemTableValues()
    {
        TableModel tb=function_BL.ItemTable();
        tbItem.setModel(tb);
    }

    /**
    * @param args the command line arguments
    */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bntSelect;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbItem;
    // End of variables declaration//GEN-END:variables
    private int Count;
}
